package cn.jdy.plugins.websocket;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;


/**
 * @desc   服务端处理器和握手接口配置
 * @author ningqian
 * @date   2017-3-22
 */
@Configuration  
@EnableWebSocket 
public class WebSocketConfig implements WebSocketConfigurer{

	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//		 registry.addHandler(myHandler(), "/webSocketServer").addInterceptors(new HandShake());
	//	System.out.println("registerWebSocketHandlers()....");
		 registry.addHandler(myHandler(), "/websck").addInterceptors(new HandShake());  
		 registry.addHandler(myHandler(), "/myHandler").addInterceptors(new HandShake()).setAllowedOrigins("*").withSockJS();  
	//	 registry.addHandler(myLiveHandler(), "/myLiveHandler").addInterceptors(new HandShake()).setAllowedOrigins("*").withSockJS();  
//		 registry.addHandler(myHandler(), "/myHandler").addInterceptors(new HttpSessionHandshakeInterceptor()).setAllowedOrigins("*").withSockJS();  
	}

	@Bean
	public WebSocketHandler myHandler() {
		System.out.println("myHandler()....");
		return new WebsocketEndPoint();  
	}
//	@Bean
//	public WebSocketHandler LiveHandler() {
//		return new WebliveWebsocket();  
//	}
}
